var btnfun=function(){
    //创建XmlHttpRequest组建
    var xmlHttpReq= new XMLHttpRequest();
    //设置回调函数
    var getfun=function(){
        if(xmlHttpReq.readyState==4 ){
            if(xmlHttpReq.status==200 || xmlHttpReq.status==201){
                var res=xmlHttpReq.responseText;
                var parsed = JSON.parse(res);
                for (var i = 0; i < parsed.length; i++) {
                    var li = document.createElement("li");
                    var label = document.createElement("label");
                    var input = document.createElement("input");
                    input.type = "checkbox";
                    input.checked = parsed[i].completed;
                    var textNode = document.createTextNode(parsed[i].name);
                    label.appendChild(input);
                    label.appendChild(textNode);
                    li.appendChild(label);
                    document.getElementById("aa").appendChild(li);
                }
            }else{
                alert(xmlHttpReq.status);
                //alert('Problem retrieving XML data');
            }
        }
    }
    xmlHttpReq.onreadystatechange = getfun;
    //初始化XmlHttpRequest组建
    url="http://localhost/api/items";
    xmlHttpReq.open('POST',url,true);
    xmlHttpReq.setRequestHeader('Content-Type','application/json');
    //发送请求
    var item = {
        name: "zxcv",
        completed: false
    };
    var item2 = {
        name: "jjj",
        completed: true
    };
    var item3 = {
        name: "xyw",
        completed: false
    };
    xmlHttpReq.send(JSON.stringify(item3));
    //xmlHttpReq.send();

    
}
btnfun();

